<?php /*a:3:{s:61:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\user\purview.html";i:1742284629;s:62:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\header.html";i:1742284578;s:61:"D:\phpstudy_pro\WWW\oldi-erp\app\admin\view\public\style.html";i:1742284578;}*/ ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ERP</title>

    <link rel="stylesheet" href="/static/css/element-ui@2.15.14.css">
    <script src="/static/js/vue.js"></script>
    <script src="/static/js/element-ui@2.15.14.js"></script>
    <script src="/static/js/axios.js"></script>
    <script src="/static/js/qs.js"></script>
    <script src="/static/js/config.js"></script>
    <script src="/static/js/echart.js"></script>
</head>

<style scoped>
    .el-select-dropdown {
      padding: 0;
    }
    </style>
 <style>
    html,
    body,
    #app {
        padding: 0;
        margin: 0;
    }    
    #contenr{
        padding: 0;
        margin: 10px;
    }
</style>

<body>
    <div id="app"  v-cloak>
        <div id="contenr">
        <el-card style="width: 80%;" >   
            <el-breadcrumb separator="/">
                <el-breadcrumb separator="/">
                    <el-page-header @back="goBack"  content="用户列表"></el-page-header>
                </el-breadcrumb>        
            </el-breadcrumb>
        </el-card>
        <br>      
      
          <el-card style="width: 80%;" >   
          
            <el-form :inline="true" :model="createForm"  :rules="rules" size="mini"  ref="refcreateForm">    
                <el-form-item label="管理组" prop="groups" >
                    <template>    
                        <div class="group-items" >
                            <el-checkbox-group    v-model="createForm.groups">
                                <el-checkbox v-for="item in authGroup" :key="item.id" :label="item.id" >
                                    {{item.title}}
                                </el-checkbox> 
                            </el-checkbox-group>
                        </div>
                    </template>
                </el-form-item>
                <div>
                    <el-form-item label="用户名称" prop="username">
                        <el-input v-model="createForm.username" class="inputwidth" placeholder="请输入用户登录名" clearable filterable ></el-input>
                    </el-form-item>
                    <span style="margin-left: 2px;font-size: 12px;">用户名称用来登录系统的账户名称</span>
                </div>
                <div>
                    <el-form-item label="用户昵称" prop="nickname" >
                        <el-input v-model="createForm.nickname" class="inputwidth" placeholder="请输入用户昵称" clearable filterable></el-input>
                    </el-form-item>
                    <span style="margin-left: 2px;font-size: 12px;">用户昵称用来在前台页面展示，请尽量用真实的姓名</span>
               </div>
               <div>
                    <el-form-item label="用户密码" prop="password" >
                        <el-input v-model="createForm.password" class="inputwidth" placeholder="请输入用户密码" clearable filterable></el-input>
                    </el-form-item>
                 
                </div>
                <div>
                    <el-form-item label="手机号码"  prop="phone"  >
                        <el-input v-model="createForm.phone" class="inputwidth" placeholder="请输入手机号码" clearable filterable style="margin-left: 8px;"></el-input>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="邮  箱" prop="email">
                        <el-input v-model="createForm.email" class="inputwidth" placeholder="请输入邮箱" clearable filterable style="margin-left: 28px;width: 210px;" ></el-input>
                    </el-form-item>
                </div>
                <div>                 
                    <el-form-item label="状态" prop="status" >
                        <el-radio-group v-model="createForm.status" >
                          <el-radio label=1>允许登录</el-radio>
                          <el-radio label=0>禁止登录</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>
                <div>
                    <el-form-item label="所属仓库" >
                        <el-select v-model="createForm.storgeid" placeholder="请选择仓库" clearable filterable>
                            <el-option v-for="item in storagelist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div style="margin-left: 15px;"> 
                    <el-form-item style="margin-top: 30px;">
                        <el-button type="primary" v-if="iscreateVisible===true" @click="checkSubmits">确认添加</el-button>
                        <el-button type="primary" v-if="iscreateVisible===false" @click="checkSubmits">确认修改</el-button>
                    </el-form-item>
                </div>      
            </el-form> 
        </el-card>
    </div>      


    <script>
        new Vue({
            el: '#app',
            data: function () {
                return { 
                    authGroup:<?php echo $authGroup; ?>,  //权限 组信息
                    storagelist:<?php echo $storagelist; ?>, //仓库列表   
                    searchForm:{
                        id: <?php echo htmlentities($id); ?>        
                    },
                    id: <?php echo htmlentities($id); ?> ,     
                    createForm:{
                        email:'',
                        status:'1',
                        storgeid:'',
                        phone:'',
                        nickname:'',
                        username:'',
                        password:'',
                        groups:[],      
                         
                        id: <?php echo htmlentities($id); ?>           
                    },
                    num:'',//获取id 是否是数字
                    iscreateVisible: false,//判断过来是添加还是数字
                    rules: {
						groups: [
                            { required: true, message: '管理组不能为空', trigger: 'change' }
                        ],				
						username:[
							{ required: true, message: '用户名称不能为空', trigger: 'blur' },
							{ min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' },
                            // { pattern:  /^[0-9]+$/, message: '手机号码必须为数字值',trigger: 'blur'}
							{ validator: this.validateUsername, trigger: 'blur' }
						],
						nickname:[
							{ required: true, message: '用户昵称不能为空', trigger: 'blur' }
						],					
						phone:[					
							{ min: 11, max: 11, message: '手机号码应在11位', trigger: 'blur' },
							{ pattern:  /^[0-9]+$/, message: '手机号码必须为数字值',trigger: 'blur'}
						],
						password:[	
                            { required: true, message: '密码不能为空', trigger: 'blur' },						
							{ min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
						],
						email:[
							{ pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/, message: '请输入合法邮箱',trigger: 'blur'}
						],
                  }                        
                   
                }
            },
            mounted(){           
            //   this.getDatalist()
            //  
            this.num = Number.parseInt(this.createForm.id, 10);
              if(Number.isFinite(this.num)){
                  this.iscreateVisible = false;
                  this.getlist()
              }else{
                this.iscreateVisible = true;
              }
            },
            methods: {        
                  //返回上一个页面
                goBack() {              
                    window.location.href = '/Admin/user/index';
                },            
                
                 async getlist() {
                    let loading = this.$loading({
                          lock: true,
                          text: '数据加载中···',
                          spinner: 'el-icon-loading',
                          background: 'rgba(0, 0, 0, 0.7)'
                    });
                    const res = await axios.post('/Admin/user/purview', {params: this.searchForm})
                    loading.close()
                    if (res.status !== 1) {
                        return this.$message.error(res.info);
                    }                
                    
                    this.createForm = res.info                   
                    this.createForm.status=res.info.status.toString() //转字符串
                    if(res.info.storgeid){
                        this.createForm.storgeid=Number.parseInt(res.info.storgeid)    //转数字
                    }
                  
                    if(res.info.id){
                         this.createForm.password = '******'
                    }                
                 
                 },
                
              
                //确认提交修改
                async checkSubmits(){
                  this.$refs.refcreateForm.validate(async valid => {                 
                      if (!valid) return;
                      let loading = this.$loading({
                          lock: true,
                          text: '数据保存中···',
                          spinner: 'el-icon-loading',
                          background: 'rgba(0, 0, 0, 0.7)'
                            });
           
                      axios.post('/Admin/user/create_purview', {params: this.createForm}).then(res => {
                          loading.close()
                          if (res.status !== 1) {
                              return this.$message.error(res.info);                  
                          }
                      
                          this.$message.success('操作成功');
                          window.location.href = '/Admin/user/index';                      
                      }).catch(err => {
                          console.log(err)
                      })
                  })
                },
               
            }
        })
        </script>
        
      </html>
      